package com.bluestone.config;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

import com.bluestone.scripts.Project;
import com.bluestone.util.Util;

public class BluestoneConfigTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		generateBluestoneConfig();

	}
	
	public static void generateBluestoneConfig(){
		try {
			BluestoneConfig config = new BluestoneConfig();
			ActionConfig clickAction = new ActionConfig();
			clickAction.setType("click");
			clickAction.setClassName("com.bluestone.action.ClickAction");
			config.putActionConfig(clickAction);
			
			ActionConfig moveAction = new ActionConfig();
			moveAction.setType("move");
			moveAction.setClassName("com.bluestone.action.MoveAction");
			config.putActionConfig(moveAction);
			
			ActionConfig delayAction = new ActionConfig();
			delayAction.setType("delay");
			delayAction.setClassName("com.bluestone.action.DelayAction");
			config.putActionConfig(delayAction);
			
			ActionConfig inputtextAction = new ActionConfig();
			inputtextAction.setType("inputtext");
			inputtextAction.setClassName("com.bluestone.action.InputTextAction");
			config.putActionConfig(inputtextAction);
			
			ActionConfig inputkeyAction = new ActionConfig();
			inputkeyAction.setType("inputkey");
			inputkeyAction.setClassName("com.bluestone.action.InputKeyAction");
			config.putActionConfig(inputkeyAction);
			
			ActionConfig maxpageAction = new ActionConfig();
			maxpageAction.setType("maxpage");
			maxpageAction.setClassName("com.bluestone.action.MaxPageAction");
			config.putActionConfig(maxpageAction);
			
			ActionConfig closepageAction = new ActionConfig();
			closepageAction.setType("closepage");
			closepageAction.setClassName("com.bluestone.action.ClosePageAction");
			config.putActionConfig(closepageAction);	
			
			ActionConfig runAction = new ActionConfig();
			runAction.setType("run");
			runAction.setClassName("com.bluestone.action.RunAction");
			config.putActionConfig(runAction);	
			
			ActionConfig selectlistAction = new ActionConfig();
			selectlistAction.setType("selectlist");
			selectlistAction.setClassName("com.bluestone.action.SelectListAction");
			config.putActionConfig(selectlistAction);
			
			ActionConfig checktrueAction = new ActionConfig();
			checktrueAction.setType("checktrue");
			checktrueAction.setClassName("com.bluestone.action.CheckTrueAction");
			config.putActionConfig(checktrueAction);
			
			ActionConfig checkfalseAction = new ActionConfig();
			checkfalseAction.setType("checkfalse");
			checkfalseAction.setClassName("com.bluestone.action.CheckFalseAction");
			config.putActionConfig(checkfalseAction);
			
			ActionConfig winrunAction = new ActionConfig();
			winrunAction.setType("winrun");
			winrunAction.setClassName("com.bluestone.action.WinrunAction");
			config.putActionConfig(winrunAction);
			
			ActionConfig focusAction = new ActionConfig();
			focusAction.setType("focus");
			focusAction.setClassName("com.bluestone.action.FocusAction");
			config.putActionConfig(focusAction);
			
			ActionConfig saveAsAction = new ActionConfig();
			saveAsAction.setType("saveAs");
			saveAsAction.setClassName("com.bluestone.action.SaveAsAction");
			config.putActionConfig(saveAsAction);	
			
			ActionConfig compareImageAction = new ActionConfig();
			compareImageAction.setType("compareImage");
			compareImageAction.setClassName("com.bluestone.action.CompareImageAction");
			config.putActionConfig(compareImageAction);		
			
			ActionConfig backpageAction = new ActionConfig();
			backpageAction.setType("backpage");
			backpageAction.setClassName("com.bluestone.action.BackPageAction");
			config.putActionConfig(backpageAction);		
			
			ActionConfig checkrgbAction = new ActionConfig();
			checkrgbAction.setType("checkrgb");
			checkrgbAction.setClassName("com.bluestone.action.CheckRGBAction");
			config.putActionConfig(checkrgbAction);		
			
			ActionConfig checkbrowserAction = new ActionConfig();
			checkbrowserAction.setType("checkbrowser");
			checkbrowserAction.setClassName("com.bluestone.action.CheckBrowserAction");
			config.putActionConfig(checkbrowserAction);			
			
			ActionConfig minpageAction = new ActionConfig();
			minpageAction.setType("minpage");
			minpageAction.setClassName("com.bluestone.action.MinPageAction");
			config.putActionConfig(minpageAction);	
			
			ActionConfig resetkeysAction = new ActionConfig();
			resetkeysAction.setType("resetkeys");
			resetkeysAction.setClassName("com.bluestone.action.ResetKeysAction");
			config.putActionConfig(resetkeysAction);
			
			ActionConfig closeallpagesAction = new ActionConfig();
			closeallpagesAction.setType("closeallpages");
			closeallpagesAction.setClassName("com.bluestone.action.CloseAllPagesAction");
			config.putActionConfig(closeallpagesAction);
			
			ActionConfig callfunctionAction = new ActionConfig();
			callfunctionAction.setType("callfunction");
			callfunctionAction.setClassName("com.bluestone.action.CallFunctionAction");
			config.putActionConfig(callfunctionAction);	
			
			ActionConfig openurlAction = new ActionConfig();
			openurlAction.setType("openurl");
			openurlAction.setClassName("com.bluestone.action.OpenURLAction");
			config.putActionConfig(openurlAction);	
			
			ActionConfig setcurrentpageAction = new ActionConfig();
			setcurrentpageAction.setType("setcurrentpage");
			setcurrentpageAction.setClassName("com.bluestone.action.SetCurrentPageAction");
			config.putActionConfig(setcurrentpageAction);
			
			ActionConfig openpageAction = new ActionConfig();
			openpageAction.setType("openpage");
			openpageAction.setClassName("com.bluestone.action.OpenPageAction");
			config.putActionConfig(openpageAction);		
			
			ActionConfig closecurrentpageAction = new ActionConfig();
			closecurrentpageAction.setType("closecurrentpage");
			closecurrentpageAction.setClassName("com.bluestone.action.CloseCurrentPageAction");
			config.putActionConfig(closecurrentpageAction);	
			
			ActionConfig removecurrentpageAction = new ActionConfig();
			removecurrentpageAction.setType("removecurrentpage");
			removecurrentpageAction.setClassName("com.bluestone.action.RemoveCurrentPageAction");
			config.putActionConfig(removecurrentpageAction);			
			
			ActionConfig nextfocusAction = new ActionConfig();
			nextfocusAction.setType("nextfocus");
			nextfocusAction.setClassName("com.bluestone.action.NextFocusAction");
			config.putActionConfig(nextfocusAction);
			
			ActionConfig screenshotAction = new ActionConfig();
			screenshotAction.setType("screenshot");
			screenshotAction.setClassName("com.bluestone.action.ScreenshotAction");
			config.putActionConfig(screenshotAction);
			
			ActionConfig saveasimageAction = new ActionConfig();
			saveasimageAction.setType("saveasimage");
			saveasimageAction.setClassName("com.bluestone.action.SaveAsImageAction");
			config.putActionConfig(saveasimageAction);	
			
			ActionConfig saveasfileAction = new ActionConfig();
			saveasfileAction.setType("saveasfile");
			saveasfileAction.setClassName("com.bluestone.action.SaveAsFileAction");
			config.putActionConfig(saveasfileAction);
			
			ActionConfig checkprojectAction = new ActionConfig();
			checkprojectAction.setType("checkproject");
			checkprojectAction.setClassName("com.bluestone.action.CheckProjectAction");
			config.putActionConfig(checkprojectAction);	
			
			ActionConfig startserverAction = new ActionConfig();
			startserverAction.setType("startserver");
			startserverAction.setClassName("com.bluestone.action.StartServerAction");
			config.putActionConfig(startserverAction);	
			
			ActionConfig stopserverAction = new ActionConfig();
			stopserverAction.setType("stopserver");
			stopserverAction.setClassName("com.bluestone.action.StopServerAction");
			config.putActionConfig(stopserverAction);			
			
			ActionConfig setproxyAction = new ActionConfig();
			setproxyAction.setType("setproxy");
			setproxyAction.setClassName("com.bluestone.action.SetProxyAction");
			config.putActionConfig(setproxyAction);	
			
			ActionConfig unsetproxyAction = new ActionConfig();
			unsetproxyAction.setType("unsetproxy");
			unsetproxyAction.setClassName("com.bluestone.action.UnsetProxyAction");
			config.putActionConfig(unsetproxyAction);	
			
			ActionConfig altkeydownAction = new ActionConfig();
			altkeydownAction.setType("altkeydown");
			altkeydownAction.setClassName("com.bluestone.action.AltKeyDownAction");
			config.putActionConfig(altkeydownAction);
			
			ActionConfig altkeyupAction = new ActionConfig();
			altkeyupAction.setType("altkeyup");
			altkeyupAction.setClassName("com.bluestone.action.AltKeyUpAction");
			config.putActionConfig(altkeyupAction);	
			
			ActionConfig breakAction = new ActionConfig();
			breakAction.setType("break");
			breakAction.setClassName("com.bluestone.action.BreakAction");
			config.putActionConfig(breakAction);				
			
			ActionConfig controlkeydownAction = new ActionConfig();
			controlkeydownAction.setType("controlkeydown");
			controlkeydownAction.setClassName("com.bluestone.action.ControlKeyDownAction");
			config.putActionConfig(controlkeydownAction);
			
			ActionConfig controlkeyupAction = new ActionConfig();
			controlkeyupAction.setType("controlkeyup");
			controlkeyupAction.setClassName("com.bluestone.action.ControlKeyUpAction");
			config.putActionConfig(controlkeyupAction);	
			
			ActionConfig jtypeAction = new ActionConfig();
			jtypeAction.setType("jtype");
			jtypeAction.setClassName("com.bluestone.action.JTypeAction");
			config.putActionConfig(jtypeAction);	
			
			ActionConfig robotAction = new ActionConfig();
			robotAction.setType("robot");
			robotAction.setClassName("com.bluestone.action.RobotAction");
			config.putActionConfig(robotAction);
			
			ActionConfig assertAction = new ActionConfig();
			assertAction.setType("assert");
			assertAction.setClassName("com.bluestone.action.AssertAction");
			config.putActionConfig(assertAction);
			
			
			AssertorConfig clipboardAssertor = new AssertorConfig();
			clipboardAssertor.setName("clipboardAssertor");
			config.putAssertorConfig(clipboardAssertor);
			
			AssertorConfig loggingAssertor = new AssertorConfig();
			loggingAssertor.setName("loggingAssertor");
			loggingAssertor.setClassName("com.bluestone.assertor.LoggingAssertor");
			loggingAssertor.setIsDefault("Y");
			FilterConfig filter = new FilterConfig();
			filter.setName("AIVRFilter");
			filter.setClassName("com.bluestone.assertor.AIVRLoggingFilter");
			loggingAssertor.putFilterConfig(filter);
			config.putAssertorConfig(loggingAssertor);
			
			
			AssertorConfig webproxyAssertor = new AssertorConfig();
			webproxyAssertor.setName("webproxyAssertor");
			config.putAssertorConfig(webproxyAssertor);
			
			ActionHandlerConfig actionHandler = new ActionHandlerConfig();
			actionHandler.setType("PREP_POST");
			actionHandler.setClassName("com.bluestone.report.ActionTimeHandler");
			config.putActionHandlerConfig(actionHandler);

			ExpAttributesHandlerConfig command = new ExpAttributesHandlerConfig();
			command.setClassName("com.bluestone.report.CommandExpAttributeHandler");
			command.setTarget("COMMAND");
			config.putExpAttributesHandlerConfig(command);
			
			ExpAttributesHandlerConfig testcase = new ExpAttributesHandlerConfig();
			testcase.setClassName("com.bluestone.report.TestCaseExpAttributeHandler");
			testcase.setTarget("TESTCASE");
			config.putExpAttributesHandlerConfig(testcase);	
			
			ExpAttributesHandlerConfig testsuite = new ExpAttributesHandlerConfig();
			testsuite.setClassName("com.bluestone.report.TestSuiteExpAttributeHandler");
			testsuite.setTarget("TESTSUITE");
			config.putExpAttributesHandlerConfig(testsuite);	
			
			ExpAttributesHandlerConfig project = new ExpAttributesHandlerConfig();
			project.setClassName("com.bluestone.report.ProjectExpAttributeHandler");
			project.setTarget("PROJECT");
			config.putExpAttributesHandlerConfig(project);			
			
			JAXBContext context = JAXBContext.newInstance(config.getClass());
			Marshaller marshaller = context.createMarshaller();
			marshaller.setProperty("jaxb.formatted.output",new Boolean(true));
			
			// create parent folder if it doesn't exist to avoid IOException
			String path =  "./bluestone_cfg.xml";
			File file = new File(path);
			if ( file.getParentFile()!=null && !file.getParentFile().exists() ) {
				file.getParentFile().mkdirs();
			}	
			marshaller.marshal(config, file);
			
		}catch(Exception me) {
			Util.getLogger().error("fail to save bluestone config "+me);
		}			
	}	

}
